<template>
  <div id="home">
    <p class="title">推荐歌曲</p>
    <van-row gutter="10">
      <van-col span="8" v-for="item in list" :key="item.id">
        <van-image height="3rem" fit="cover" lazy-load :src="item.picUrl" />
        <p class="song_name">{{ item.name }}</p>
      </van-col>
    </van-row>
    <p class="title">最新音乐</p>
    <div>
      <van-cell-group>
        <!-- <van-cell
          v-for="item in newList"
          :key="item.id"
          :title="item.name"
          :label="item.song.artists[0].name"
          center
        >
          <template #right-icon>
            <van-icon name="play-circle-o" size="20" />
          </template>
        </van-cell> -->
        <SongItem 
         v-for="item in newList"
          :key="item.id"
          :id="item.id"
          :title="item.name"
          :label="item.song.artists[0].name"
        ></SongItem>
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import SongItem from '@/components/SongItem.vue'
import { getData,getNewsData } from "@/api/recom.js";
export default {
  components:{
    SongItem
  },
  name: "Home",
  data() {
    return {
      list: [],
      newList:[],
    };
  },
  created() {
    this.getList();
    this.getNewList()
  },
  methods: {
    async getList() {
      const { code, result } = await getData({ limit: 6 });
      if (code === 200) {
        this.list = result;
      }
      // console.log(result);
    },

    async getNewList(){
      const {code,result} = await getNewsData()
      if(code === 200){
        this.newList= result
      }
      console.log(result);
    }
  },
};
</script>

<style scoped>
/* 标题 */
.title {
  padding: 10px 8px;
  margin: 0 0 8px 0;
  background-color: #eee;
  color: #333;
  font-size: 15px;
}
/* 推荐歌单 - 歌名 */
.song_name {
  font-size: 12px;
  padding: 0 3px;
  margin-bottom: 10px;
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
  -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
  -webkit-line-clamp: 2; /** 显示的行数 **/
  overflow: hidden; /** 隐藏超出的内容 **/
}
</style>
